﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using VonaJobs.DAL.DAO;

namespace VonaJobs.DAL.Gatway
{
    public class EventGateway : DBGateway
    {
        public string SaveNewEvent(Event aevent)
        {
            try
            {
                ConnectionObj.Open();
                CommandObj.CommandText =
                    string.Format("insert into tblEvent values(@EventType,@EventPosition,@EventImagePath)");
                CommandObj.Parameters.Clear();
                CommandObj.Parameters.Add("@EventType", SqlDbType.NVarChar).Value = aevent.EventType;
                CommandObj.Parameters.Add("@EventPosition", SqlDbType.Int).Value = aevent.EventPosition;
                CommandObj.Parameters.Add("@EventImagePath", SqlDbType.NVarChar).Value = aevent.EventImagePath;



                CommandObj.ExecuteNonQuery();
                return "New event created successfully";
            }
            catch (Exception)
            {
                throw new Exception("Message Not Send, Server Error !");
            }
            finally
            {
                if (ConnectionObj != null && ConnectionObj.State == ConnectionState.Open)
                {
                    ConnectionObj.Close();
                }

            }
        }
        public string UpdateEvent(Event aevent)
        {
            try
            {
                ConnectionObj.Open();
                CommandObj.CommandText =
                    string.Format("Update tblEvent Set EventType='{0}',EventPosition='{1}',EventImagePath='{2}' where Id='{3}'", aevent.EventType, aevent.EventPosition, aevent.EventImagePath);
                CommandObj.ExecuteNonQuery();
                return "Event update successfully";
            }
            catch (Exception)
            {
                throw new Exception("Event update successfull, Server Error !");
            }
            finally
            {
                if (ConnectionObj != null && ConnectionObj.State == ConnectionState.Open)
                {
                    ConnectionObj.Close();
                }

            }
        }
        public string DeleteEvent(Event aevent)
        {
            try
            {
                ConnectionObj.Open();
                CommandObj.CommandText =
                    string.Format("Delete * from where Id='{0}'",aevent.Id);
                CommandObj.ExecuteNonQuery();
                return "Delete event successfully";
            }
            catch (Exception)
            {
                throw new Exception("Event update successfull, Server Error !");
            }
            finally
            {
                if (ConnectionObj != null && ConnectionObj.State == ConnectionState.Open)
                {
                    ConnectionObj.Close();
                }

            }
        }
       
    }
}